﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Petaframe.DataAccess
{
    /// <summary>
    /// Her tablo için CRUD işlemlerine ait sorguları oluşturur.
    /// </summary>
    internal class TableQueries
    {
        private string _DeleteQuery = string.Empty;
        private string _UpdateQuery = string.Empty;
        private string _InsertQuery = string.Empty;        
        readonly TableInfo _tableInfo;
        public TableQueries(TableInfo _table)
        {
            if (_table == null)
                throw new NullReferenceException("tableInfo parameter");

            _tableInfo = _table;
        }
     
        public string InsertQuery
        {
            get
            {
                if (string.IsNullOrWhiteSpace(_InsertQuery))
                {
                    ICommandStringBuilder insertCommand = new InsertCommandBuilder();
                    _InsertQuery = insertCommand.CommandString(_tableInfo).ToString();
                }
                return _InsertQuery;
            }
           
        }
        public string UpdateQuery
        {
            get
            {
                if (string.IsNullOrWhiteSpace(_UpdateQuery))
                {
                    ICommandStringBuilder updateCommand = new UpdateCommandBuilder();
                    _UpdateQuery = updateCommand.CommandString(_tableInfo).ToString();
                }
                return _UpdateQuery;
            }
           
        }
        public string DeleteQuery
        {
            get
            {
                if (string.IsNullOrWhiteSpace(_DeleteQuery))
                {
                    ICommandStringBuilder deleteCommand = new DeleteCommandBuilder();
                    _DeleteQuery = deleteCommand.CommandString(_tableInfo).ToString();
                }
                return _DeleteQuery;
            }
           
        }
    }
}
